﻿function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
}

$(function () {


    try {
        $(".DatePicker").datepicker({
            "dateFormat": "DD, d MM, yy",
            changeMonth: true,
            changeYear: true
        });

        $('#calendar-icon').click(function () {
            $(".DatePicker").datepicker("show");
        });

        $("input.DatePicker").bind('paste', function () { return false; });
        $("input.DatePicker").bind('cut', function () { return false; });
        $("input.DatePicker").bind('keydown', function () { limitText($(this).get(0), 0); });
        $("input.DatePicker").bind('keyup', function () { limitText($(this).get(0), 0); });
    } catch (ex) { }
});


window.open_popup = function (url, name, width, height, center) {
    try {
        var _name = name || "WND_New";
        width = width || "600px";
        height = height || "600px";
        center = center || true;
        var _paramsA = []; _paramsA.push("resizable=yes"); _paramsA.push("status=yes"); _paramsA.push("scrollbars=yes"); _paramsA.push("toolbar=no");
        this.m_windowLeft = document.all ? "left" : "screenX";
        this.m_windowTop = document.all ? "top" : "screenY";
        var _params = "width=" + width + ",height=" + height;
        if (center) {
            _params += "," + this.m_windowLeft + "=" + Math.floor((window.screen.width - parseInt(width)) / 2);
            _params += "," + this.m_windowTop + "=" + Math.floor((window.screen.height - parseInt(height)) / 2);
        }
        if (_params) { _params += "," + _paramsA.join(","); }
        //        window.open(url, _name, _params);
        window.open(url);
    } catch (ex) { alert(ex.message); }
}



jQuery(document).ready(function () {
    jQuery('#modalIFrame').attr('src', '/EmailToFriend.aspx?url=' + encodeURIComponent(window.location.href) + "&title=" + encodeURIComponent(document.title));
    jQuery('#comments_frame').attr('src', '/Comments.aspx?popup=t&url=' + encodeURIComponent(window.location.href) + "&title=" + encodeURIComponent(document.title));
});

window.hideCommentsModal = function () {
    jQuery('#comment-modal').modal('hide')
}
window.hideReferToFriendModal = function () {
    jQuery('#email-to-friend-modal').modal('hide')
}



function resize_popup() {

    var img = jQuery('#NewsImage');

    var maxWidth = Math.max(img.width() + 100, 635);

    var maxHeight = 600; //Math.max(img.height() + 180, 570);

    //        console.log(maxWidth);
    //        console.log(img.height() + 180);
    //        console.log(maxHeight);

    window.resizeTo(maxWidth, maxHeight);

}